<!DOCTYPE html>
<html lang="en"  xmlns:th="http://www.thymeleaf.org">
<head>
    <meta charset="UTF-8">
    <title>修改用户</title>
    <link rel="stylesheet" href="../../../component/pear/css/pear.css" />
</head>
<body>
<form class="layui-form" action="">
    <div class="mainBox">
        <div class="main-container">
            <div class="main-container">
                <div class="layui-form-item">
                    <label class="layui-form-label">编号</label>
                    <div class="layui-input-block">
                        <input type="text" readonly id="typeid" name="typeid" lay-verify="title" autocomplete="off" placeholder="请输入标题" class="layui-input">
                    </div>
                </div>
                <div class="layui-form-item">
                    <label class="layui-form-label">名称</label>
                    <div class="layui-input-block">
                        <input type="text" id="typename" name="typename" lay-verify="title" autocomplete="off" placeholder="请输入标题" class="layui-input">
                    </div>
                </div>
               
               
            
                
                 <div class="layui-form-item">
                    <label class="layui-form-label">备注</label>
                    <div class="layui-input-block">
                        <input type="text" id="typeinfo" name="typeinfo" lay-verify="title" autocomplete="off" placeholder="请输入标题" class="layui-input">
                    </div>
                </div>
                
            </div>
        </div>
    </div>
    <div class="bottom">
        <div class="button-container">
            <button type="submit" class="pear-btn pear-btn-primary pear-btn-sm" lay-submit="" lay-filter="user-save">
                <i class="layui-icon layui-icon-ok"></i>
                提交
            </button>
            <button type="reset" class="pear-btn pear-btn-sm">
                <i class="layui-icon layui-icon-refresh"></i>
                重置
            </button>
        </div>
    </div>
</form>
<script src="../../../component/layui/layui.js"></script>
<script src="../../../component/pear/pear.js"></script>
<script>


layui.use(['form','jquery'],function(){
    let form = layui.form;
    let $ = layui.jquery;
    
    //使用layui中包含那个jquery
    $(function(){
    	
    	//获取localStorage中的值

    	$("#typeid").val(localStorage.getItem("typeid"));
    	$("#typename").val(localStorage.getItem("typename"));
    	$("#typeinfo").val(localStorage.getItem("typeinfo")); 

    });

    //表单中的按钮的提交事件
    form.on('submit(user-save)', function(data){

        //JSON.parse(...) =>将字符串解析为json对象
        //JSON.stringify 对象转换为json格式字符串
        console.log(JSON.stringify(data.field));
        $.ajax({
            url:'/jja2103_zmall_v2/type.do?op=update', //url ajax提交目标地址
            data:JSON.stringify(data.field), //data 提交到servlet的数据,json格式字符串
            dataType:'json', //接收到servlet 返回的数据格式  json
            contentType:'application/json', //提交给servlet 数据格式 json
            type:'post', //提交方法
            success:function(result){  //请求成功后
                if(result.msg==="success"){
                    layer.msg("修改成功!",{icon:1,time:1000},function(){
                        parent.layer.close(parent.layer.getFrameIndex(window.name));//关闭当前页
                        parent.layui.table.reload("type-table"); //父窗口table重新加载
                    });
                }else{
                    layer.msg("修改失败!",{icon:2,time:1000});
                }
            }
        })
        return false;
    });
})
</script>
<script>
</script>
</body>
</html>
